/* eslint-disable react/prefer-es6-class */
import createReactClass from 'create-react-class';
import PropTypes from 'prop-types';

const Index = createReactClass({
    getDefaultProps () {
        return {
            name: 'zs',
            age: 18
        };
    },
    getInitialState () {
        return {
            count: 0
        };
    },
    componentDidMount () {
        console.log(this.props);
    },
    increment () {
        this.setState((pre) => ({
            count: pre.count + 1
        }));
    },
    decrement () {
        this.setState((pre) => ({
            count: pre.count - 1
        }));
    },
    render () {
        const { props } = this;
        return (
            <div>
                {props.name} --- {props.age}
                <div>{this.state.count}</div>
                <button onClick={this.increment}>+</button>
                <button onClick={this.decrement}>-</button>
            </div>
        );
    }
});

Index.propTypes = {
    name: PropTypes.string.isRequired,
    age: PropTypes.number.isRequired
};

export default Index;
